package com.qingcheng.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.qingcheng.entity.Result;
import com.qingcheng.pojo.user.User;
import com.qingcheng.service.user.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.web.bind.annotation.*;

/**
 * Welcome to the most Amazing IntelliJ IIIDEA.
 * Creat0r: ^_^ fffantianxing ^_^
 * Date: 2019-07-15
 * Time: 20:59
 */
@RequestMapping("user")
@RestController
public class UserController {
    @Reference
    private UserService userService;

    @GetMapping("send")
    public Result sendSms(String phone) {
        userService.sendSms(phone);
        return new Result();
    }

    @PostMapping("save")
    public Result save(@RequestBody User user, String smsCode) {

        //密码加密
        BCryptPasswordEncoder encoder = new BCryptPasswordEncoder();
        String encode = encoder.encode(user.getPassword());
        user.setPassword(encode);
        userService.add(user, smsCode);
        return new Result();
    }
}
